package com.example.schedule;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.function.Predicate;

/**
 * Create by Fanketly on 2021/11/4
 * Gitee:https://gitee.com/fanketly
 */

public class SimpleList {

    public static <T> T find(List<T> list, Predicate<? super T> predicate) {
        for (T t : list)
            if (predicate.test(t)) return t;
        return null;
    }

    public static <T> List<T> findSome(List<T> list, Predicate<? super T> predicate) {
        List<T> tList = arrayListOf();
        for (T t : list)
            if (predicate.test(t))
                tList.add(t);
        if (tList.size() != 0)
            return tList;
        return null;
    }

    @SafeVarargs
    public static <T> List<T> listOf(T... e) {
        return Arrays.asList(e);
    }

    public static <T> ArrayList<T> arrayListOf() {
        return new ArrayList<>();
    }

    @SafeVarargs
    public static <T> ArrayList<T> arrayListOf(T... e) {
        return (ArrayList<T>) Arrays.asList(e);
    }


}
